ARD2  RC2
Airbag Reference Demonstrator using MPC5604P
debug.c
Go to the documentation of this file.
00001 
00016 #include "derivative.h"
00017 #include "HAL.h"
00018 #include "CRC.h"
00019 #include "FLASH.h"
00020 #include "Freemaster.h"
00021 //#include "Labview.h"
00022 #include "DSPI.h"
00023 #include "LIN_UART.h"
00024 //#include "Utils.h"
00025 #include "SIU.h"
00026 #include "CGM.h"
00027 #include "edma.h"
00028 #include "MMA68xx.h"
00029 #include "Compile_Options.h"
00030 #include "ADC.h"
00031 #include "UTILS.h"
00032 #include "MailDelivery.h"
00033 #include "MailScheduler.h"
00034 
00035 #ifdef USE_DEMO_BOARD
00036 #define LED1  ('D'), ((uint8_t)4u)
00037 #define LED2  ('D'), ((uint8_t)5u)
00038 #define LED3  ('D'), ((uint8_t)6u)
00039 #define LED4  ('D'), ((uint8_t)7u)
00040 #endif
00041 /*
00042  ******************************************************************************
00043  * Constants
00044  ******************************************************************************
00045  */
00046 const uint8_t cu8ASCIIDelete[] = { 0x08u, 0xFFu, 0x08u };
00047 const uint8_t gau8Welcome[] = "ARD2: Welcome. \n\r";
00048 const uint8_t cu8NewLine[]   = "\n\r";
00049 /*
00050  ******************************************************************************
00051  * Globals
00052  ******************************************************************************
00053  */
00054 uint32_t gu32;
00055 uint16_t gu16Counter;
00056 uint8_t  gu8Counter;
00057 uint32_t au32[2u];
00058 uint8_t  gau8[9] = {
00059   '1', '2', '3', '4', '5', '6', '7', '8', '9'
00060 };
00061 /*
00062  ******************************************************************************
00063  * Freemaster stuff
00064  ******************************************************************************
00065  */
00066 //#ifdef USE_FREEMASTER
00067 
00068 /* Table with global variables */
00069 FMSTR_TSA_TABLE_BEGIN(first_table)
00070     FMSTR_TSA_RO_VAR(gu16Counter,    FMSTR_TSA_UINT16)
00071 FMSTR_TSA_TABLE_END()
00072 FMSTR_TSA_TABLE_BEGIN(second_table)
00073     FMSTR_TSA_RO_VAR(gu8Counter,    FMSTR_TSA_UINT8)
00074 FMSTR_TSA_TABLE_END()
00075 
00076 /* Table with Tables */
00077 FMSTR_TSA_TABLE_LIST_BEGIN()
00078     FMSTR_TSA_TABLE(first_table)
00079     FMSTR_TSA_TABLE(second_table)
00080 FMSTR_TSA_TABLE_LIST_END()
00081 
00082 FMSTR_APPCMD_RESULT myhandler(FMSTR_APPCMD_CODE /*nAppcmd*/, FMSTR_APPCMD_PDATA /*pData*/, FMSTR_SIZE /*nDataLen*/)
00083 {
00084     // the return value is used as the application command result code
00085     return 0x10;    
00086 }
00087 
00088 //#endif
00089 /*
00090  ******************************************************************************
00091  * main
00092  ******************************************************************************
00093  */
00094 
00095 
00096 const uint32_t cu32ADCCh1Config = \
00097   (ADC_CH_ISR_EN | ADC_CH15 | (ADC_MODULE_1 << 8u));
00098 
00099 int main(void) 
00100 {
00101   ADCChConfig_t tMyADCConfig;
00102   TCD_t tMyDefaultConfig;
00103   uint8_t  u8Status;
00104   uint16_t au16Results[64];
00105   
00106   
00107   u8Status = u8fnMCUInit();
00108   
00109   /* Disable any existing conversions before we move on */
00110   u8Status = u8fnADCNormalConversionEnable(0, CLEAR);
00111   
00112   tMyADCConfig.P.ChDMAEn = TRUE;
00113   tMyADCConfig.P.ChIsrEn = CLEAR;
00114   tMyADCConfig.P.Channel = 12;
00115   tMyADCConfig.P.DMACh = 8;
00116   tMyADCConfig.P.Instance = 0;
00117   
00118   u8Status = u8fnADCChannelConfig((const ADCChConfig_t*)&tMyADCConfig, 
00119                                   (uint16_t*)&au16Results);
00120   
00121   /* Source Address will always be the ADC result */
00122   tMyDefaultConfig.P.SADDR = (((uint32_t)&ADC_0.CDR[12].R) + 2u);
00123   /* Destination address is our output vehicle (DSPI, for example) */
00124   tMyDefaultConfig.P.DADDR = (uint32_t)&au16Results;
00125   /* Modulus is 0 */
00126   tMyDefaultConfig.P.SMOD = CLEAR;
00127   tMyDefaultConfig.P.DMOD = CLEAR;
00128   /* We will transfer 32-bit words */
00129   tMyDefaultConfig.P.SSIZE = DMA_SIZE_16_BIT;
00130   tMyDefaultConfig.P.DSIZE = DMA_SIZE_16_BIT;
00131   tMyDefaultConfig.P.SOFF = 0u; /* Offset per minor loop (in bytes) */
00132   tMyDefaultConfig.P.DOFF = 2u; /* Destination offset per minor loop */
00133   tMyDefaultConfig.P.NBYTES = 2u; /* Inner loop transfer count (in bytes) */
00134   tMyDefaultConfig.P.SLAST = CLEAR;
00135   tMyDefaultConfig.P.CITERE_LINK = CLEAR;
00136   tMyDefaultConfig.P.BITERE_LINK = CLEAR;
00137   tMyDefaultConfig.P.CITER = 64; /* Times we'll execute our minor loop */
00138   tMyDefaultConfig.P.BITER = 64; /* Memory for the loop */
00139   tMyDefaultConfig.P.D_REQ = TRUE; /* Clear HW Start requests after major loop is done */
00140   
00141   tMyDefaultConfig.P.DLAST_SGA = -128; /* Last destination offset */
00142   tMyDefaultConfig.P.MAJORLINKCH = CLEAR;
00143   tMyDefaultConfig.P.BWC = DMA_BWC_4_CYCLE_STALL;
00144   tMyDefaultConfig.P.MAJORE_LINK = CLEAR; /* Disable ch2ch linking */
00145   tMyDefaultConfig.P.E_SG = CLEAR;
00146   
00147   tMyDefaultConfig.P.INT_HALF = CLEAR;
00148   tMyDefaultConfig.P.INT_MAJ = TRUE;
00149   tMyDefaultConfig.P.START = CLEAR;
00150   
00151   vfnDMAConfig(&tMyDefaultConfig, 8);
00152   
00153   /* Route it adequately */
00154   vfnDMAMUXInit((uint8_t)tMyADCConfig.P.DMACh, DMA_SOURCE_ADC0, CLEAR, TRUE);
00155   
00156   /* Enable HW signaling to channel 8 */
00157   EDMA.SERQR.R = (uint8_t)tMyADCConfig.P.DMACh;
00158   
00159   /* Now that the DMA and the ADC are configured, start ADC conversion */
00160   u8Status = u8fnADCNormalConversionEnable(0, TRUE);
00161   
00162   
00163   
00164   
00165   
00166 #ifdef USE_FREEMASTER
00167    /************************* FREEMASTER *************************************/
00168 
00169    FMSTR_Init();
00170 #endif
00171 //  CRC32_1((uint8_t*)&gau8, 0x09, (uint32_t*)&gu32);
00172   for(;;)
00173   {
00174 //    gu8Counter++;
00175 //    gu16Counter++;
00176 #ifdef USE_FREEMASTER
00177     /************************* FREEMASTER *************************************/
00178     FMSTR_Poll();
00179 #endif
00180     
00181   }
00182   gu8Counter++;
00183   
00184 }/* End MAIN */
00185 
00186 #define cCrc16Polynomial   (0x1021)  // G(x) = x16 + x12 + x5 + 1
00187 uint16_t u16fnCalcCrc16(uint8_t *ui8BasePtr, uint8_t ui8BufLen, uint16_t ui16CrcStart)
00188 {
00189   uint8_t ui8CrcIdx;
00190   uint8_t ui8CrcLoop;
00191   uint8_t ui8CrcTdata;
00192   uint16_t ui16Crcword;
00193  
00194   ui16Crcword = ui16CrcStart;
00195  
00196   for (ui8CrcIdx = 0 ; ui8CrcIdx < ui8BufLen ; ui8CrcIdx++ )
00197   {
00198     ui8CrcTdata = *ui8BasePtr;      
00199     ui8BasePtr++;                  
00200  
00201     for (ui8CrcLoop = 0; ui8CrcLoop < 8;ui8CrcLoop++ )
00202     {
00203       if (((ui8CrcTdata ^ (uint8_t)(ui16Crcword >> 8)) & 0x80) != 0 )
00204       {
00205           ui16Crcword = ui16Crcword << 1;
00206           ui16Crcword = ui16Crcword ^ cCrc16Polynomial;
00207       }
00208       else
00209       {
00210           ui16Crcword = ui16Crcword << 1;
00211       }
00212       ui8CrcTdata = ui8CrcTdata << 1;
00213     } 
00214   } 
00215   return(ui16Crcword);
00216 }
00217 
00218 void vfnTestSystemForHWDebug(void)
00219 {
00220   uint8_t au8Array[] = "SERIAL INTERFACE IS OK.";
00221   
00222   /* CAN */
00223   vfnToggleOutputPin('A', 1, TRUE);
00224   vfnToggleOutputPin('A', 1, CLEAR);
00225   vfnToggleOutputPin('A', 0, TRUE);
00226   vfnToggleOutputPin('A', 0, CLEAR);
00227   /* Reset gyro */
00228   vfnToggleOutputPin('C', 10, TRUE);
00229   vfnToggleOutputPin('C', 10, CLEAR);
00230   vfnToggleOutputPin('C', 9, TRUE);
00231   vfnToggleOutputPin('C', 9, CLEAR);
00232   /* LIN Enable */
00233   vfnToggleOutputPin('A', 10, TRUE);
00234   vfnToggleOutputPin('A', 10, CLEAR);
00235   /* LED */
00236   vfnToggleOutputPin('D', 0, TRUE);
00237   vfnToggleOutputPin('D', 0, CLEAR);
00238   vfnToggleOutputPin('D', 1, TRUE);
00239   vfnToggleOutputPin('D', 1, CLEAR);
00240   vfnToggleOutputPin('D', 2, TRUE);
00241   vfnToggleOutputPin('D', 2, CLEAR);
00242   vfnToggleOutputPin('D', 3, TRUE);
00243   vfnToggleOutputPin('D', 3, CLEAR);
00244   vfnToggleOutputPin('D', 4, TRUE);
00245   vfnToggleOutputPin('D', 4, CLEAR);
00246   
00247   (void)u8fnUARTWrite(1, (const uint8_t*)&au8Array, sizeof(au8Array));
00248   u8fnUARTRead(1, (const uint8_t*)&au8Array, 5);
00249   
00250   return;
00251 }
00252 
00253 /*
00254  ******************************************************************************
00255  *
00256  *  End of file.
00257  *
00258  ******************************************************************************
00259  */